package com.woniu.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

@Component
public class SendEmail {
    @Value("${spring.mail.username}")
    private  String sendPerson;
    @Autowired
    private JavaMailSenderImpl javaMailSender;

    public  void sendMsg(String tittle,String msg,String email){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setSubject(tittle);
        mailMessage.setText(msg);
        mailMessage.setTo(email);    //收件人的邮箱
        mailMessage.setFrom(sendPerson);  //发件人的邮箱，和配置的username保持一致
        javaMailSender.send(mailMessage);
    }
}
